home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MPW Oberon 2.1168 / OExamples / DAMemory.mod < prev    next >
Encoding:
Text File  |  1995-07-03  |  4.5 KB  |  160 lines  |  [TEXT/MPS ]

  1. (*
  2.  File DAMemory.p
  3.  
  4.  Copyright Apple Computer, Inc. 1985-1988
  5.  All rights reserved.
  6. *)
  7.  
  8. (*$R-*) (* No range checking  *)
  9.  
  10. MODULE DAMemory;
  11.  
  12. IMPORT SYSTEM, Types, Memory, QuickdrawText, Quickdraw, Events, Windows,
  13.        Devices, TextUtils, Files, Desk, OSUtils, Fonts;
  14.  
  15. TYPE
  16.     EventPtr = POINTER TO Events.EventRecord;
  17.     CtlBlkPtr = POINTER TO OSUtils.CntrlParamBlockRec;
  18.  
  19. (*$S Main*) (* put routines in segment "Main" *)
  20.  
  21. PROCEDURE RsrcID(dCtl: Devices.DCtlPtr): INTEGER;
  22. BEGIN
  23.     RETURN BOR($C000, ASH(BNOT(dCtl.dCtlRefNum), 5))
  24. END RsrcID;
  25.  
  26. (*$Calling Pascal*)
  27. PROCEDURE DRVROpen*(ctlPB: OSUtils.ParmBlkPtr; dCtl: Devices.DCtlPtr): Types.OSErr;
  28. VAR     
  29.     savePort:    Quickdraw.GrafPtr;
  30.     heapGrow:    LONGINT;
  31.     myWindow:    Windows.WindowPtr;
  32. BEGIN
  33.     IF dCtl.dCtlWindow = NIL THEN
  34.         Quickdraw.GetPort (savePort);
  35.             myWindow := Windows.GetNewWindow(RsrcID(dCtl), NIL, Windows.WindowPtr(-1));
  36.             myWindow.windowKind := dCtl.dCtlRefNum;  (* show a DA owns this window *)
  37.         dCtl.dCtlWindow := myWindow;    (* let the desk manager know too *)
  38.         heapGrow := Memory.MaxMem (heapGrow);
  39.         Quickdraw.SetPort (savePort)
  40.     END;
  41.     RETURN Types.noErr
  42. END DRVROpen;
  43.  
  44.  
  45. PROCEDURE DRVRClose*(ctlPB: OSUtils.ParmBlkPtr; dCtl: Devices.DCtlPtr): Types.OSErr;
  46. BEGIN
  47.     IF dCtl.dCtlWindow # NIL THEN
  48.         Windows.DisposeWindow (dCtl.dCtlWindow);
  49.         dCtl.dCtlWindow := NIL
  50.     END;
  51.     RETURN Types.noErr
  52. END DRVRClose;
  53.  
  54.  
  55. PROCEDURE DRVRControl*(ctlPB: CtlBlkPtr; dCtl: Devices.DCtlPtr): Types.OSErr;
  56. (*$Calling Oberon*)
  57.  
  58.     PROCEDURE DrawWindow;
  59.     VAR 
  60.         saveZone:            Memory.THz;
  61.         tempStr,VolName:    Types.Str255;
  62.         freeBytes:            LONGINT;
  63.         ourID:                INTEGER;
  64.  
  65.         PROCEDURE PrintNum (num:LONGINT);    (*outputs the number in plain text*)
  66.         VAR 
  67.             outStr: Types.Str255;
  68.         BEGIN
  69.             TextUtils.NumToString (num,outStr);
  70.             QuickdrawText.TextFace (0);                    (* the empty set* = Plain *)
  71.             QuickdrawText.DrawString (outStr);
  72.             QuickdrawText.TextFace (Types.bold)
  73.         END PrintNum;
  74.     
  75.         PROCEDURE GetVolStuff;    
  76.         VAR
  77.             error:    Types.OSErr;
  78.             myParamBlk: Files.HVolumeParamBlockRec;
  79.         BEGIN
  80.             myParamBlk.ioNamePtr := SYSTEM.ADR(VolName);
  81.             myParamBlk.ioVRefNum := 0;         (* if ioVRefNum and ioVolIndex are zero, *)
  82.             myParamBlk.ioVolIndex := 0;        (* go for the default volume. *)
  83.             error := Files.PBHGetVInfo (SYSTEM.ADR(myParamBlk), FALSE);
  84.             
  85.             (* ioVFrBlk is an unsigned integer.  If > 32767 and assigned
  86.               to freeBytes (a LongInt), Oberon will think it is negative
  87.               and sign extend it.  The expression below masks off this
  88.               high word so that freeBytes is correctly signed.  See
  89.               tech note #157 more a more in-depth explanation. *)
  90.             freeBytes := BAND(myParamBlk.ioVFrBlk, $0000FFFF) * myParamBlk.ioVAlBlkSiz;
  91.         END GetVolStuff;
  92.  
  93.         PROCEDURE PrtRsrcStr(index: INTEGER);
  94.         BEGIN
  95.             TextUtils.GetIndString(tempStr, ourID, index);
  96.             QuickdrawText.DrawString(tempStr);
  97.         END PrtRsrcStr;
  98.  
  99.     BEGIN    (* DrawWindow *)
  100.         ourID := RsrcID(dCtl);
  101.         
  102.         QuickdrawText.TextMode (Quickdraw.srcCopy);
  103.         QuickdrawText.TextFont (Fonts.monaco);
  104.         QuickdrawText.TextSize (9);
  105.         QuickdrawText.TextFace (Types.bold);
  106.  
  107.         Quickdraw.MoveTo (6,10); PrtRsrcStr(1);    (* "AppHeap: " *)
  108.         saveZone := Memory.GetZone();
  109.         Memory.SetZone (Memory.ApplicZone());
  110.         PrintNum (Memory.FreeMem()); 
  111.         
  112.         PrtRsrcStr(2);    (* " SysHeap: " *)
  113.         Memory.SetZone (Memory.SystemZone());
  114.         PrintNum (Memory.FreeMem());
  115.         Memory.SetZone (saveZone);         (* always put things back the way you found them *)
  116.  
  117.         PrtRsrcStr(3);        (* " Disk: " *)
  118.         GetVolStuff;
  119.         PrintNum (freeBytes);
  120.  
  121.         PrtRsrcStr(4);        (* " free on " *)
  122.         QuickdrawText.TextFace (Types.underline);
  123.         QuickdrawText.DrawString (VolName);
  124.     END DrawWindow;
  125.  
  126. VAR
  127.     eventAt:    EventPtr;    (* Pointer to our event *)
  128.     
  129. BEGIN
  130.     Quickdraw.SetPort(dCtl.dCtlWindow); (* the desk manager restores thePort*)
  131.     CASE ctlPB.csCode OF
  132.         Desk.accEvent:
  133.             SYSTEM.GET(SYSTEM.ADR(ctlPB.csParam), eventAt);    (* get the event pointer *)
  134.             IF eventAt.what = Events.updateEvt THEN (* we only handle one event *)
  135.                 Windows.BeginUpdate (Windows.WindowPtr(eventAt.message));
  136.                     DrawWindow;
  137.                 Windows.EndUpdate (Windows.WindowPtr(eventAt.message));
  138.             END| (* of accEvent Case *)
  139.  
  140.         Desk.accRun:         (* our periodic call *)
  141.             DrawWindow|
  142.         ELSE (* igore other events *)
  143.     END; (* of CASE *)
  144.     RETURN Types.noErr
  145. END DRVRControl;
  146.  
  147. (*$Calling Pascal*)
  148. PROCEDURE DRVRPrime* (ctlPB: OSUtils.ParmBlkPtr; dCtl: Devices.DCtlPtr): Types.OSErr;
  149. BEGIN
  150.     RETURN Types.noErr;
  151. END DRVRPrime;
  152.  
  153. PROCEDURE DRVRStatus* (ctlPB: OSUtils.ParmBlkPtr; dCtl: Devices.DCtlPtr): Types.OSErr;
  154. BEGIN
  155.     RETURN Types.noErr;
  156. END DRVRStatus;
  157. (*$Calling Oberon*)
  158.  
  159. END DAMemory.
  160.